import type { TableColumn } from '@/components/core/dynamic-table';

export type TableListItem = API.ApproveListPageResultItem;
export type TableColumnItem = TableColumn<TableListItem>;

let reviewStatusList = [
  {
    label: '全部',
    value: 0,
  },
  {
    label: '待审批',
    value: 1,
  },
  {
    label: '同意',
    value: 2,
  },
  {
    label: '不同意',
    value: 3,
  },
];

const caseReviewStatus = (val) => {
  switch (val) {
    case 1:
      return '待审批';
    case 2:
      return '同意';
    case 3:
      return '不同意';
    default:
      return '-';
  }
};

const caseTextColor = (val) => {
  switch (val) {
    case 1:
      return 'color: #F5820F';
    case 2:
      return 'color: #09B840';
    case 3:
      return 'color: #E22C4C';
    default:
      return 'color: #999999';
  }
};

let checkResultList = [
  {
    label: '全部',
    value: 0,
  },
  {
    label: '合格',
    value: 1,
  },
  {
    label: '不合格',
    value: 2,
  },
];
const caseCheckResult = (val) => {
  switch (val) {
    case 1:
      return '合格';
    case 2:
      return '不合格';
    default:
      return '-';
  }
};

export const baseColumns: TableColumnItem[] = [
  {
    title: '关键词',
    dataIndex: 'keyword',
    hideInTable: true,
    searchField: 'keyword',
    formItemProps: {
      labelWidth: 55,
      componentProps: () => {
        return {
          placeholder: '可输入任务编号、场所名称搜索',
          autocomplete: 'off',
          disabledLabelWidth: true,
        };
      },
    },
  },
  {
    title: '任务编号',
    width: 120,
    dataIndex: 'taskNo',
    hideInSearch: true,
  },
  {
    title: '场所名称',
    width: 120,
    dataIndex: 'placeName',
    hideInSearch: true,
  },
  {
    title: '审批状态',
    width: 120,
    dataIndex: 'reviewStatus',
    resizable: true,
    formItemProps: {
      component: 'Select',
      componentProps: () => ({
        options: reviewStatusList,
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => (
      <div style={caseTextColor(record.reviewStatus)}>{caseReviewStatus(record.reviewStatus)}</div>
    ),
  },
  {
    title: '结果判定',
    width: 120,
    dataIndex: 'checkResult',
    resizable: true,
    formItemProps: {
      component: 'Select',
      componentProps: () => ({
        options: checkResultList,
      }),
      defaultValue: 0,
    },
    customRender: ({ record }) => caseCheckResult(record.checkResult),
  },
  {
    title: '检查人',
    dataIndex: 'checkerName',
    width: 120,
    hideInSearch: true,
  },
  {
    title: '检查时间',
    dataIndex: 'endCheckTime',
    width: 120,
    hideInSearch: true,
  },
];
